if(ENABLE_RUST)
# 配置Rust编译
find_program(CARGO cargo REQUIRED)
set(RUST_TARGET "thumbv7em-none-eabihf") # STM32F4目标
set(ENV{CARGO_BUILD_TARGET} thumbv7em-none-eabihf)

add_custom_command(
        OUTPUT "${CMAKE_SOURCE_DIR}/Rust/target/thumbv7em-none-eabihf/release/libembedded_rust.a"
        COMMAND cargo  build --manifest-path ${CMAKE_SOURCE_DIR}/Rust/Cargo.toml --release
        COMMAND cbindgen --lang c --cpp-compat --output ${CMAKE_SOURCE_DIR}/Rust/include/rust_lib.h
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Rust
        COMMENT "Building Rust library"
)

add_custom_target(rust_lib DEPENDS "${CMAKE_SOURCE_DIR}/Rust/target/thumbv7em-none-eabihf/release/libembedded_rust.a")
endif ()